package com.py.credit.utils;


import javax.xml.bind.JAXB;
import java.io.StringReader;
import java.io.StringWriter;

/**
 * 封装了XML转换成object，object转换成XML的代码
 * 
 * @author wangpei
 * 
 */
public class SubmitConvXmlUtils {
	
	/**
	 * 将对象直接转换成String类型的 XML输出
	 * 
	 * @param obj
	 * @return
	 */
	public static String convert2Xml(Object obj) {
		// 创建输出流
		StringWriter sw = new StringWriter();
		JAXB.marshal(obj,sw);
		return sw.toString();
	}
 
 
	/**
	 * 将String类型的xml转换成对象
	 */
	@SuppressWarnings("unchecked")
	public static Object convertXml2Object(Class clazz, String xmlStr) {
		StringReader sr = new StringReader(xmlStr);
		Object xmlObject = JAXB.unmarshal(sr, clazz);
		return xmlObject;
	}
 
}

